package com.yanqu.road.server.manager.activity.apprentice.handler.impl;

import com.yanqu.road.entity.activity.apprentice.ApprenticeEffectBuffProject;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeProjectConfig;
import com.yanqu.road.entity.activity.apprentice.data.ApprenticeBuffProjectData;
import com.yanqu.road.entity.activity.apprentice.data.ApprenticeUserData;
import com.yanqu.road.entity.activity.apprentice.enums.ApprenticeProjectSortEnum;
import com.yanqu.road.server.manager.activity.apprentice.handler.ApprenticeProjectHandler;
import com.yanqu.road.server.manager.activity.apprentice.handler.param.*;

import java.util.List;
import java.util.Map;

public class ApprenticeDoProjectType5Handler implements ApprenticeProjectHandler {

    /**
     * 执行项目
     * @param req
     * @return
     */
    @Override
    public ApprenticeDoProjectResp doProject(ApprenticeDoProjectReq req) {
        return null;
    }

    @Override
    public void countTalentTypeAddRate(ApprenticeCountTalentAddRateReq req) {

    }

    /**
     * |接下来{0}次行程，|传奇及以上品质课程天资{1}，以下品质天资{2}。
     * @param req
     */
    @Override
    public void countSortTypeAddRate(ApprenticeCountSortAddRateReq req) {
        ApprenticeBuffProjectData buffProjectData = req.getBuffProjectData();
        //buff次数减一
        buffProjectData.addNum(-1);
        //加成MAP
        Map<Integer, Integer> resultMap = req.getResultMap();
        //项目配置
        ApprenticeProjectConfig projectConfig = req.getProjectConfig();
        String[] paramArr = projectConfig.getParam().split("\\|");
        int jgType = Integer.parseInt(paramArr[0]);//间隔的品质
        int addRate1 = Integer.parseInt(paramArr[1]) - 1000;
        int addRate2 = Integer.parseInt(paramArr[2]) - 1000;
        for (ApprenticeProjectSortEnum sortEnum : ApprenticeProjectSortEnum.values()) {
            if (sortEnum.getType() == ApprenticeProjectSortEnum.SORT_TYPE_0.getType()) {
                //特殊项目属于无双以上
                int oldRate = resultMap.getOrDefault(sortEnum.getType(), 0);
                resultMap.put(sortEnum.getType(), oldRate + addRate1);
                continue;
            }
            if (sortEnum.getType() >= jgType) {
                int oldRate = resultMap.getOrDefault(sortEnum.getType(), 0);
                resultMap.put(sortEnum.getType(), oldRate + addRate1);
            } else {
                int oldRate = resultMap.getOrDefault(sortEnum.getType(), 0);
                resultMap.put(sortEnum.getType(), oldRate + addRate2);
            }
        }
        //生效buff结果结果集注入
        List<ApprenticeEffectBuffProject> effectBuffProjects = req.getEffectBuffProjects();
        ApprenticeEffectBuffProject effectBuffProject = new ApprenticeEffectBuffProject(buffProjectData.getProjectId());
        effectBuffProjects.add(effectBuffProject);
    }
}
